﻿//*************************************************************************
//面向服务的协作式智能交通系统仿真软件SoC-ITSS v2.1 alpha
//发布单位：西北工业大学--巴黎高科MINES机器人与群智能系统联合实验室
//团队负责人：张凯龙 Zhang Kailong
//团队成员：张大方、杨安胜、王敏、谢策、王雨佳、谢尘玉等
//联系我们：kl.zhang@nwpu.edu.cn
//2012-2021
//*************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;

namespace CyberCarSimulation.Utils
{
    class ImageUtils
    {

        public static void BitMapUnion(string imageFolder, int RoadWidthNum, int RoadHeightNum)
        {
            var firstBitmap = new Bitmap(Path.Combine(imageFolder, "RoadMap1.bmp"));
            var secondBitmap = new Bitmap(Path.Combine(imageFolder, "RoadMap1.bmp"));
            int newWidth = 0;
            int newHeight = 0;
            for (int i = 1; i <= RoadWidthNum; i++) {
                newWidth += firstBitmap.Width;
            }
            for (int j = 1; j <= RoadHeightNum; j++) {
                newHeight += firstBitmap.Height;
            }

            var newBitmap = new Bitmap(newWidth, newHeight);
            for (int m = 0; m < RoadWidthNum; m++) {
                for (int n = 0; n < RoadHeightNum; n++) {
                    //复制图片
                    for (var i = 0; i <= firstBitmap.Width - 1; i++)
                    {
                        for (var j = 0; j <= firstBitmap.Height - 1; j++)
                        {
                            var c = firstBitmap.GetPixel(i, j);
                            newBitmap.SetPixel(firstBitmap.Width * m + i, firstBitmap.Width * n + j, c);
                        }
                    }

                }
            }

            //    for (var i = 0; i <= firstBitmap.Width - 1; i++)
            //    {
            //        for (var j = 0; j <= firstBitmap.Height - 1; j++)
            //        {
            //            var c = firstBitmap.GetPixel(i, j);
            //            newBitmap.SetPixel(i, j, c);
            //        }
            //    }

            //for (var i = 0; i <= secondBitmap.Width - 1; i++)
            //{
            //    for (var j = 0; j <= firstBitmap.Height - 1; j++)
            //    {
            //        var c = secondBitmap.GetPixel(i, j);
            //        newBitmap.SetPixel(i + firstBitmap.Width, j, c);
            //    }
            //}
            newBitmap.Save(Path.Combine(imageFolder, "New.bmp"));
        }  
    }
}
